package com.zhg.controller;

import java.io.IOException;

import javax.websocket.CloseReason;
import javax.websocket.OnClose;
import javax.websocket.OnError;
import javax.websocket.OnMessage;
import javax.websocket.OnOpen;
import javax.websocket.Session;
import javax.websocket.server.ServerEndpoint;

import com.zhg.handler.MyHandler;
import com.zhg.vo.User;


@ServerEndpoint("/socket")
public class MessageController {

	// 收到消息触发事件
	@OnMessage
	public void onMessage(String message, Session session) throws IOException, InterruptedException {
	    
	}

	// 打开连接触发事件
	@OnOpen
	public void onOpen(Session session) {
	    String id = session.getId();
	    User user = new User();
	    user.setId(id);
	    if(null != MyHandler.userMap.get(id)) {
	    	MyHandler.userMap.put(id, user);
	    }
	}

	// 关闭连接触发事件
	@OnClose
	public void onClose(Session session, CloseReason closeReason) {
	    
	}

	// 传输消息错误触发事件
	@OnError
	public void onError(Throwable error) {
	    
	}
	
}
